#include<iostream>
#include<pthread.h>
#include<unistd.h>
pthread_mutex_t mutex = PTHREAD_MUTEX_INITIALIZER;
pthread_cond_t cond = PTHREAD_COND_INITIALIZER;

void* action(void* arg)
{
    char* str = (char*)arg;
    while(1)
    {
        pthread_mutex_lock(&mutex);
        pthread_cond_wait(&cond,&mutex);

        std::cout<<str<<std::endl;

        pthread_mutex_unlock(&mutex);

    }
}

int main()
{
    pthread_t t1,t2;
    pthread_create(&t1,NULL,action,(void*)"我是线程A");
    pthread_create(&t2,NULL,action,(void*)"我是线程B");

    while(1)
    {
        sleep(1);
        pthread_cond_signal(&cond);
    }
    
    pthread_join(t1,NULL);
    pthread_join(t2,NULL);
    return 0;
}